***** Replication File for "Going Nativist: Going Nativist: How Nativism and Economic Ideology Interact to Shape Beliefs about Global Trade"
***** This file contains code to replicate variable coding and appendix summary data; run before replicating analyses if starting from uncoded data
***** 17 November 2020
***** This file already contains factor scores for beliefs about globalization, generated in MPlus (see PRS_Table1 for implementation)

log using "C:\Users\f002mrh\Dropbox\Trade Attitudes\Data and Code\Replication Files for FPA\\UKcodinglog.txt" 
**** Demographic characteristics, Partisanship, Ideology
*Education
*University graduate
gen university=0
replace university=1 if education_level==16
replace university=1 if education_level==17
replace university=1 if education_level==18

*Race
tab ethnicity
gen white = 0
replace white =1 if ethnicity==1 | ethnicity==2
tab ethnicity, gen(eth_)

*Gender
recode w2sex1 (1=1) (2=0), gen(male)

*Age
gen age1 = 0
replace age1 = 1 if age < 30
gen age2 = 0
replace age2 = 1 if age < 45 & age > 29
gen age3 = 0
replace age3 = 1 if age > 44 & age < 65
gen age4 = 0
replace age4 = 1 if age > 64

*Partisanship
gen labour = 0
replace labour = 1 if w2UKparty1==2 | w2UKparty2==1 | w2UKparty3==3 
gen libdem = 0 
replace libdem = 1 if w2UKparty1==3 | w2UKparty2==2 | w2UKparty3==1  
gen conserv = 0 
replace conserv = 1 if w2UKparty1==1 | w2UKparty2==3 | w2UKparty3==2  
gen ukip = 0
replace ukip=1 if w2UKparty1==7 | w2UKparty2==7 | w2UKparty3==7
gen snp = 0
replace snp=1 if w2UKparty1==5 | w2UKparty2==5 | w2UKparty3==5
gen green = 0
replace green=1 if w2UKparty1==6 | w2UKparty2==6 | w2UKparty3==6
gen noparty = 0
replace noparty = 1 if  w2UKparty1==10 | w2UKparty2==10 | w2UKparty3==10
gen pidother = 0
replace pidother = 1 if w2UKparty1==4 | w2UKparty1==8 | w2UKparty1==9 | w2UKparty2==4 | w2UKparty2==8 | w2UKparty2==9 | w2UKparty3==8 | w2UKparty3==9
gen pidother2 = 0
replace pidother2 = 1 if ukip==1 | snp==1 | green==1 | noparty==1 | pidother==1

*Without UKIP on the right
gen partyright = .
replace partyright = 1 if conserv==1 
replace partyright = 0 if labour==1 | libdem==1 | green==1 | snp==1

*With UKIP on the right
gen partyright2 = .
replace partyright2 = 1 if conserv==1 | ukip==1
replace partyright2 = 0 if labour==1 | libdem==1 | green==1 | snp==1

*Employment Status
tab work_status, gen(work_)

gen workfull = 0
replace workfull = 1 if work_1==1
gen workpart = 0 
replace workpart = 1 if work_2==1 | work_3==1
gen workstudent = 0
replace workstudent = 1 if work_4==1
gen workretired = 0
replace workretired = 1 if work_5==1
gen workunemp = 0
replace workunemp = 1 if work_6==1 | work_7==1
gen workother = 0
replace workother = 1 if work_8==1


*Household income
tab household_income, gen(inc_)
gen inc20 = 0
replace inc20 = 1 if inc_1==1 | inc_2==1 | inc_3==1 | inc_4==1 | inc_5==1
gen inc2035 = 0
replace inc2035 = 1 if inc_6==1 | inc_7==1 | inc_8==1
gen inc3560 = 0 
replace inc3560 = 1 if inc_9==1 | inc_10==1 | inc_11==1 | inc_12==1
gen inc60up = 0
replace inc60up = 1 if inc_13==1 | inc_14==1 | inc_15==1 | inc_16==1

*code don't know and prefer not to answer as missing
foreach var of varlist inc20 inc2035 inc3560 inc60up {
replace `var' = . if inc_17==1 | inc_18==1
}



****Appendix Section 1.1: Nativism and Economic Perceptions Measurement 
*Percent of sample dk on each item - range from 3.21 to 14.53% in the U.K. sample
*Nativism
* DK = 5.13%
tab w2eupan1 
* DK = 3.21%
tab w2eupan2
*DK = 3.33%
tab w2eupan3
* DK = 4.02%
tab w2eupan4 
*DK = 3.68%
tab w2eupan5
*DK = 9.10%
tab w2eupan6
*DK = 8.68%
tab w2eupan7
*DK = 3.68%
tab w2eupan8
*DK = 14.53%
tab w2eupan9
*Recode DK to midpoint*
recode w2eupan1 (6=3), gen(w2eupan1a)
recode w2eupan2 (6=3), gen(w2eupan2a)
recode w2eupan3 (6=3), gen(w2eupan3a)
recode w2eupan4 (6=3), gen(w2eupan4a)
recode w2eupan5 (6=3), gen(w2eupan5a)
recode w2eupan6 (6=3), gen(w2eupan6a)
recode w2eupan7 (6=3), gen(w2eupan7a)
recode w2eupan8 (6=3), gen(w2eupan8a)
recode w2eupan9 (6=3), gen(w2eupan9a)

*alpha = 0.9010
alpha w2eupan1a w2eupan2a w2eupan3a w2eupan4a w2eupan5a w2eupan6a w2eupan7a w2eupan8a w2eupan9a, item

*Reverse code so Nativist response is high end of scale
recode w2eupan1a w2eupan3a w2eupan6a w2eupan8a w2eupan9a (1=5) (2=4) (3=3) (4=2) (5=1)

*An additive scale
gen natism = w2eupan1a + w2eupan2a + w2eupan3a + w2eupan4a + w2eupan5a + w2eupan6a + w2eupan7a + w2eupan8a + w2eupan9a

*Alpha for two-item version = 0.68
alpha w2eupan1a w2eupan2a

*Belief in free market, market regulation (measured in previous wave)
tab w1fremkt1
tab w1regmkt1

foreach var of varlist w1fremkt1 w1regmkt1 {
gen `var'r=`var'
recode `var'r (6=3) (1=5) (2=4) (3=3) (4=2) (5=1)
}

*Additional Control Variables: 

*Retrospective economic sentiment
foreach var of varlist w2econ1 w2econ2 {
gen new`var'=`var'
recode new`var' (1=5) (2=4) (3=3) (4=2) (5=1) (6=3)
}


*Prospective economic sentiment 
foreach var of varlist w2econp1 w2econp2 {
gen new`var'=`var'
recode new`var' (6=3)
**(1=5) (2=4) (3=3) (4=2) (5=1) 
}


*Economic Sentiment (this is really only a single dimension)
factor neww2econ1 neww2econ2 neww2econp1 neww2econp2, ml
*alpha=0.80
alpha neww2econ1 neww2econ2 neww2econp1 neww2econp2, item gen(econsentimentw2)
*rescale 0 to 1
replace econsentimentw2=econsentimentw2-1
replace econsentimentw2=econsentimentw2/4 

*Universalism
tab w2Univ2f1
recode w2Univ2f1 (7=3.5), gen(Univ2f)
tab w2Univ3f1
recode w2Univ3f1 (7=3.5), gen(Univ3f)
tab w2Univ2m1
recode w2Univ2m1 (7=3.5), gen(Univ2m)
tab w2Univ3m1
recode w2Univ3m1 (7=3.5), gen(Univ3m)
*recode so high end of the scale = more commitment to universalism
recode Univ2f Univ3f Univ2m Univ3m (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)

*combine male and female responses into single variable
gen Univ2 = Univ2f 
replace Univ2 = Univ2m if Univ2m !=.
gen Univ3 = Univ3f
replace Univ3 = Univ3m if Univ3m !=.

gen univ = Univ2 + Univ3
*alpha = 0.74
alpha Univ2 Univ3

*repeat for conformity 
tab w2Conform1f1
recode w2Conform1f1 (7=3.5), gen(Conform1f)
tab w2Conform1m1
recode w2Conform1m1 (7=3.5), gen(Conform1m)
recode Conform1f Conform1m (1=6) (2=5) (3=4) (4=3) (5=2) (6=1)

*combine male and female responses into single variable
gen conform = Conform1f
replace conform = Conform1m if Conform1m !=.



**********************************
**** Coding for experimental data
*********************************

*Recode DK to midpoint*
recode w2trade3a (6=3), gen(tradea)
recode w2trade3b (6=3), gen(tradeb)

*Generate a variable for experimental condition, DK at midpoint*
gen tradeinfohi = .
replace tradeinfohi = 1 if tradea != .
replace tradeinfohi = 0 if tradeb != .

gen supptrade = .
replace supptrade = tradea if tradea != .
replace supptrade = tradeb if tradeb != .

log close

*Save the data to your directory
saveold "(directoryinformation)\PRS_replicationdata_UKcoded.dta"


